package com.wangbo.suzhengtong;

import com.alibaba.fastjson.JSONObject;
import java.io.IOException;


/**
 * @version V 1.0
 * @file TestMain.java
 * @Description: 国密测试类
 */
public class TestMain {

	public static void main(String[] args) throws IllegalArgumentException, IOException {
		 SM2();
	}
	
	
	public static void SM2() throws IllegalArgumentException, IOException {
		KeyEntity ke = SM2Utils.generateKeyPair();

		JSONObject jsonObject = new JSONObject();
		jsonObject.put("card_id", "test123");
		jsonObject.put("card_name", "姓名");
		String plainText = jsonObject.toString();
		byte[] sourceData = plainText.getBytes();
		// 国密规范正式私钥
		String prik =  ke.getPrivateKey();	
		// 国密规范正式公钥
		String pubk =ke.getPublicKey() ;
																																							// //"xxxxxxxxxxxxxxxxxxxxxxxxxxx";
		String cipherText = SM2Utils.encrypt(Util.hexToByte(pubk), sourceData);
		System.out.println("加密----:" + cipherText);

		String plain = new String(SM2Utils.decrypt(Util.hexToByte(prik), Util.hexToByte(cipherText)));
		System.out.println("解密----:" + plain);
	}



}
